const fs = require("fs");
//  自动创建 sql表
const axios = require("axios");
const CreateDB = async () => {
  fs.readdirSync(__dirname).forEach(async (file) => {
    if (file !== "index.js") {
      let db = require("./" + file);
      await db.sync({ force: true });
    }
  });
  axios.defaults.baseURL = "http://localhost:5001";
  const DataArr = [
    {
      softName: "Finder",
      softMenuInfo: ["Finder", "编辑", "窗口", "帮助"],
      iconUrl: "finder.png",
    },
    {
      softName: "启动台",
      softMenuInfo: ["视频", "编辑", "窗口", "帮助"],
      iconUrl: "launchpad.png",
    },
    {
      softName: "信息",
      softMenuInfo: ["QQ", "编辑", "窗口", "帮助"],
      iconUrl: "Message.png",
    },
    {
      softName: "图片",
      softMenuInfo: ["微信", "编辑", "窗口", "帮助"],
      iconUrl: "Photo.png",
    },
    {
      softName: "记事本",
      softMenuInfo: ["记事本", "编辑", "窗口", "帮助"],
      iconUrl: "Memorandum.png",
    },
    {
      softName: "FaceTime通话",
      softMenuInfo: ["FaceTime", "编辑", "窗口", "帮助"],
      iconUrl: "FaceTime.png",
    },
    {
      softName: "音乐",
      softMenuInfo: ["音乐", "编辑", "窗口", "帮助"],
      iconUrl: "music.png",
    },
  ];
  const DocumentArr = [
    {
      docName: "Appstore",
      fatherId: 1,
      docContain: [],
      fatherName: "Appstore",
      fileKind: "文件夹",
    },
    {
      docName: "User",
      fatherId: 1,
      docContain: [],
      fatherName: "Appstore",
      fileKind: "文件夹",
    },
    {
      docName: "照片",
      fatherId: 2,
      docContain: [],
      fatherName: "User",
      fileKind: "文件夹",
    },
    {
      docName: "下载",
      fatherId: 2,
      docContain: [],
      fatherName: "User",
      fileKind: "文件夹",
    },
    {
      docName: "文档",
      fatherId: 2,
      docContain: [],
      fatherName: "User",
      fileKind: "文件夹",
    },
    {
      docName: "zhaopian下的文件",
      fatherId: 3,
      docContain: [],
      fatherName: "照片",
      fileKind: "文件夹",
    },
    {
      docName: "照片下的文件2",
      fatherId: 3,
      docContain: [],
      fatherName: "照片",
      fileKind: "文件夹",
    },
    {
      docName: "zhaopian下的文件",
      fatherId: 3,
      docContain: [],
      fatherName: "照片",
      fileKind: "文件夹",
    },
    {
      docName: "zhaopian下的文件的文件",
      fatherId: 3,
      docContain: [],
      fatherName: "照片",
      fileKind: "文件夹",
    },
    {
      docName: "文档下的文件",
      fatherId: 3,
      docContain: [],
      fatherName: "文档",
      fileKind: "文件夹",
    },
  ];
  const Timer = setTimeout(async () => {
    for (let i = 0; i < DataArr.length; i++) {
      const res = await axios.post("/software", DataArr[i]);
    }
    for (let i = 0; i < DocumentArr.length; i++) {
      const res = await axios.post("/document", DocumentArr[i]);
    }
  }, 2000);
};
module.exports = CreateDB;
